package com.lxit.video.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lxit.video.bean.UserInfo;
import com.lxit.video.bean.VideoComment;
import com.lxit.video.dao.UserDao;
import com.lxit.video.dao.UserRepository;
import com.lxit.video.service.UserService;
import com.lxit.video.util.PageUtil;

@Service
public class UserServiceImpl implements UserService {
	@Autowired
	private UserRepository repository;

	@Override
	public List<UserInfo> login(String name, String password) {

		return repository.login(name, password);
	}

	@Override
	public List<UserInfo> admin_login(String name, String password) {

		return repository.admin_login(name, password);
	}

	@Override
	public boolean saveUser(UserInfo userInfo) {
		try {
			repository.save(userInfo);
			return false;
		} catch (Exception e) {
			return false;
		}
	}

	@Override
	public int nameCount(String name) {

		return repository.nameCount(name);
	}

	@Override
	public int phoneCount(String phone) {

		return repository.phoneCount(phone);
	}

	@Override
	public PageUtil<UserInfo> pageGetAll(Integer pageIndex, Integer pageSize, String name) {
		int total = repository.countAll(name);
		if (total > 0) {
			PageUtil<UserInfo> pageUtil = new PageUtil<>(pageIndex, pageSize, total);
			pageUtil.setRows(repository.pageGetAll(pageIndex, pageSize, name));
			return pageUtil;
		}
		return null;
	}

	@Override
	public int countAll(String name) {
		return repository.countAll(name);
	}

}